package adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;

import java.util.ArrayList;

import bean.Maintain_Combo;
import utils.MyUrl;
import utils.RequestQueueUtils;
import zhang.automobileservice.R;

/**
 * Created by Administrator on 2016/8/5.
 */
public class MaintenanceAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<Maintain_Combo> arrayList;

    public MaintenanceAdapter(Context context, ArrayList<Maintain_Combo> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return arrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.maintain_pulltorefresh_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder)convertView.getTag();
        }
        Maintain_Combo maintain_combo = arrayList.get(position);
        String url = MyUrl.Font_Url+MyUrl.ImageMain+maintain_combo.getImage();
        RequestQueueUtils.exectueNetWorkImageView(context,url,viewHolder.iv_image);

        viewHolder.tv_name.setText(maintain_combo.getName().trim());
        viewHolder.tv_com_location.setText(maintain_combo.getCom_location().trim());
        viewHolder.tv_price.setText("￥"+maintain_combo.getPrice());
        viewHolder.tv_originaPrice.setText("￥"+maintain_combo.getOriginaPrice());
        viewHolder.tv_originaPrice.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG ); //中间横线
        viewHolder.tv_count.setText(maintain_combo.getCount()+"人已预约");
        return convertView;
    }

    public static class ViewHolder {
        public View rootView;
        public NetworkImageView iv_image;
        public TextView tv_name;
        public TextView tv_com_location;
        public TextView tv_price;
        public TextView tv_originaPrice;
        public TextView tv_count;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.iv_image = (NetworkImageView) rootView.findViewById(R.id.iv_image);
            this.tv_name = (TextView) rootView.findViewById(R.id.tv_name);
            this.tv_com_location = (TextView) rootView.findViewById(R.id.tv_com_location);
            this.tv_price = (TextView) rootView.findViewById(R.id.tv_price);
            this.tv_originaPrice = (TextView) rootView.findViewById(R.id.tv_originaPrice);
            this.tv_count = (TextView) rootView.findViewById(R.id.tv_count);
        }

    }
}
